<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
     <!-- <el-form-item label="商品名" prop="goodsName">
        <el-input
          v-model="queryParams.goodsName"
          placeholder="请输入商品名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="商品状态" prop="goodsStatus">
        <el-select v-model="queryParams.goodsStatus" placeholder="请选择商品状态" clearable size="small">
            	<el-option :value="0" label="正常"></el-option>
            	<el-option :value="1" label="下架"></el-option>
            	<el-option :value="2" label="异常"></el-option>
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="商品库存" prop="goodsRepertory">
        <el-input
          v-model="queryParams.goodsRepertory"
          placeholder="请输入商品库存"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商品价格" prop="goodsMoney">
        <el-input
          v-model="queryParams.goodsMoney"
          placeholder="请输入商品价格"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商品添加时间" prop="goodsTime">
        <el-date-picker clearable size="small" style="width: 200px"
          v-model="queryParams.goodsTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择商品添加时间">
        </el-date-picker>
      </el-form-item> -->
     <!-- <el-form-item label="商品来源 0车主 1平台" prop="goodsSource">
        <el-input
          v-model="queryParams.goodsSource"
          placeholder="请输入商品来源 0车主 1平台"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
     <!-- <el-form-item label="首页显示 0否 1是" prop="goodsIndexShow">
        <el-input
          v-model="queryParams.goodsIndexShow"
          placeholder="请输入首页显示 0否 1是"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="是否新品 0否 1是" prop="goodsIsNewproduct">
        <el-input
          v-model="queryParams.goodsIsNewproduct"
          placeholder="请输入是否新品 0否 1是"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="是否折扣商品 0否 1是" prop="goodsIsDiscount">
        <el-input
          v-model="queryParams.goodsIsDiscount"
          placeholder="请输入是否折扣商品 0否 1是"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否推荐 0否 1是" prop="goodsIsRecommend">
        <el-input
          v-model="queryParams.goodsIsRecommend"
          placeholder="请输入是否推荐 0否 1是"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="是否热门 0否 1是" prop="goodsIsHot">
        <el-input
          v-model="queryParams.goodsIsHot"
          placeholder="请输入是否热门 0否 1是"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
     <!-- <el-form-item label="好评率" prop="goodsFavorableRate">
        <el-input
          v-model="queryParams.goodsFavorableRate"
          placeholder="请输入好评率"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="销量" prop="goodsSalesVolume">
        <el-input
          v-model="queryParams.goodsSalesVolume"
          placeholder="请输入销量"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商品类型—外键" prop="goodsTypeid">
        <el-input
          v-model="queryParams.goodsTypeid"
          placeholder="请输入商品类型—外键"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商品品牌标识—外键" prop="goodsBrandId">
        <el-input
          v-model="queryParams.goodsBrandId"
          placeholder="请输入商品品牌标识—外键"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="店铺标识—外键" prop="goodsRoomsid">
        <el-input
          v-model="queryParams.goodsRoomsid"
          placeholder="请输入店铺标识—外键"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="优惠券标识—外键" prop="goodsDiscountId">
        <el-input
          v-model="queryParams.goodsDiscountId"
          placeholder="请输入优惠券标识—外键"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:goods:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:goods:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:goods:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:goods:export']"
        >导出</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="goodsList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="商品名" align="center" prop="goodsName" width="100"/>
      <el-table-column label="商品图片(轮番)" align="center" prop="goodsImages" width="110"/>
      <el-table-column label="商品图片(缩略)" align="center" prop="goodsThumbnailImg" width="110">
		   <template style="width: 100px; height: 100px;border-radius: 50%;"
			   slot-scope="scope" v-if="scope.row.goodsThumbnailImg != null && scope.row.goodsThumbnailImg != ''">
				<el-popover trigger="hover" placement="top">
					<img v-for="(item, index) in scope.row.goodsThumbnailImg.split(',')" style="width: 100px;margin-left: 5px;" :key="index" :src="item" />
					<div slot="reference" class="name-wrapper"><el-tag size="medium">查看</el-tag></div>
				</el-popover>
			  </template>
	  </el-table-column>
      <el-table-column label="商品状态" align="center" prop="goodsStatus">
		  <template slot-scope="scope">
		  	{{scope.row.goodsStatus == 0 ? '正常':(scope.row.goodsStatus == 1 ? '下架' : (scope.row.goodsStatus==2 ? '异常':'null'))}}
		  </template>
	  </el-table-column>
      <el-table-column label="商品库存(个)" align="center" prop="goodsRepertory" width="100">
		  <template slot-scope="scope">
		  	{{scope.row.goodsRepertory + '个'}}
		  </template>
	  </el-table-column>
      <el-table-column label="商品价格(元)" align="center" prop="goodsMoney" width="100">
		  <template slot-scope="scope">
		  	{{scope.row.goodsMoney + '元'}}
		  </template>
	  </el-table-column>
      <el-table-column label="商品添加时间" align="center" prop="goodsTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.goodsTime, '{y}年{m}月{d} {h}时{m}分') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="商品描述" align="center" prop="goodsDetails" width="160"/>
      <el-table-column label="服务内容" align="center" prop="goodsServerContent" width="160"/>
      <el-table-column label="商品来源" align="center" prop="goodsSource">
		  <template slot-scope="scope">
		  	{{scope.row.goodsSource == 0 ? '车主':(scope.row.goodsSource == 1 ? '平台' : 'null')}}
		  </template>
	  </el-table-column>
      <el-table-column label="首页显示" align="center" prop="goodsIndexShow">
		  <template slot-scope="scope">
		  	{{scope.row.goodsIndexShow == 0 ? '否':(scope.row.goodsIndexShow == 1 ? '是' : 'null')}}
		  </template>
	  </el-table-column>
      <el-table-column label="是否新品" align="center" prop="goodsIsNewproduct">
		  <template slot-scope="scope">
		  	{{scope.row.goodsIsNewproduct == 0 ? '否':(scope.row.goodsIsNewproduct == 1 ? '是' : 'null')}}
		  </template>
	  </el-table-column>
      <el-table-column label="是否折扣" align="center" prop="goodsIsDiscount">
		  <template slot-scope="scope">
		  	{{scope.row.goodsIsDiscount == 0 ? '否':(scope.row.goodsIsDiscount == 1 ? '是' : 'null')}}
		  </template>
	  </el-table-column>
      <el-table-column label="是否推荐" align="center" prop="goodsIsRecommend">
		  <template slot-scope="scope">
		  	{{scope.row.goodsIsRecommend == 0 ? '否':(scope.row.goodsIsRecommend == 1 ? '是' : 'null')}}
		  </template>
	  </el-table-column>
      <el-table-column label="是否热门" align="center" prop="goodsIsHot">
		  <template slot-scope="scope">
		  	{{scope.row.goodsIsHot == 0 ? '否':(scope.row.goodsIsHot == 1 ? '是' : 'null')}}
		  </template>
	  </el-table-column>
      <el-table-column label="好评率(%)" align="center" prop="goodsFavorableRate">
		 <template slot-scope="scope">
		 	{{scope.row.goodsFavorableRate + '%'}}
		 </template>
	  </el-table-column>
      <el-table-column label="销量(个)" align="center" prop="goodsSalesVolume">
		  <template slot-scope="scope">
		  	{{scope.row.goodsSalesVolume + '个'}}
		  </template>
	  </el-table-column>
      <el-table-column label="商品类型" align="center" prop="goodsTypeid">
		  <template slot-scope="scope">
		  	{{scope.row.goodsType.goodsTypeTitle}}
		  </template>
	  </el-table-column>
      <el-table-column label="商品品牌" align="center" prop="goodsBrandId">
		  <template slot-scope="scope">
		  	{{scope.row.goodsBrand.goodsBrandName}}
		  </template>
	  </el-table-column>
      <el-table-column label="店铺名称" align="center" prop="goodsRoomsid">
		  <template slot-scope="scope">
		  	{{scope.row.storeManagement.storeManagementName}}
		  </template>
	  </el-table-column>
      <el-table-column label="优惠券" align="center" prop="goodsDiscountId" width="110">
		  <template slot-scope="scope">
		  	{{scope.row.discountCoupon.discountCouponName}}
		  </template>
	  </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="130">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:goods:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:goods:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改商品对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="商品名" prop="goodsName">
			<el-select v-model="form.goodsName" placeholder="请选择商品类型" style="width: 100%;">
				<el-option v-for="(item,index) in goodsList" :key = "index" :value="item.goodsId" :label="item.goodsName"></el-option>
			</el-select>
        </el-form-item>
        <el-form-item label="商品图片" prop="goodsImages">
          <el-input v-model="form.goodsImages" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="商品图片" prop="goodsThumbnailImg">
          <el-upload
              action="https://jsonplaceholder.typicode.com/posts/"
            	:auto-upload="false"
            	ref="upload"
            	list-type="picture-card"
            	:http-request="uploadFile"
            	:limit="1"
            	:on-preview="handlePictureCardPreview"
            	:on-remove="handleRemove"
            	:on-success="imageChange"
            	:file-list="imageList"
            ></el-upload>
            <el-dialog :visible.sync="dialogVisible"><img width="100%" :src="dialogImageUrl" alt="" /></el-dialog>
        </el-form-item>
        <el-form-item label="商品状态">
            <el-select v-model="form.goodsStatus" placeholder="请选择消息类型" style="width: 100%;">
				<el-option :value="0" label="正常"></el-option>
				<el-option :value="1" label="下架"></el-option>
				<el-option :value="2" label="异常"></el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="商品库存" prop="goodsRepertory">
          <el-input v-model="form.goodsRepertory" placeholder="请输入商品库存">
			  <template slot="append">个</template>
		  </el-input>
        </el-form-item>
        <el-form-item label="商品价格" prop="goodsMoney">
          <el-input v-model="form.goodsMoney" placeholder="请输入商品价格">
			  <template slot="append">元</template>
		  </el-input>
        </el-form-item>
        <el-form-item label="添加时间" prop="goodsTime">
          <el-date-picker clearable size="small" style="width: 100%"
            v-model="form.goodsTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择商品添加时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="商品描述" prop="goodsDetails">
          <el-input v-model="form.goodsDetails" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="服务内容" prop="goodsServerContent">
          <el-input v-model="form.goodsServerContent" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="商品来源" prop="goodsSource">
		  <el-select v-model="form.goodsSource" placeholder="请选择消息类型" style="width: 100%">
		  	<el-option :value="0" label="车主"></el-option>
		  	<el-option :value="1" label="平台"></el-option>
		  </el-select>
        </el-form-item>
        <el-form-item label="首页显示" prop="goodsIndexShow">
		  <el-select v-model="form.goodsIndexShow" placeholder="请选择消息类型" style="width: 100%">
		  	<el-option :value="0" label="否"></el-option>
		  	<el-option :value="1" label="是"></el-option>
		  </el-select>
        </el-form-item>
        <el-form-item label="是否新品" prop="goodsIsNewproduct">
		  <el-select v-model="form.goodsIsNewproduct" placeholder="请选择消息类型" style="width: 100%">
		  	<el-option :value="0" label="否"></el-option>
		  	<el-option :value="1" label="是"></el-option>
		  </el-select>
        </el-form-item>
        <el-form-item label="是否折扣" prop="goodsIsDiscount">
		  <el-select v-model="form.goodsIsDiscount" placeholder="请选择消息类型" style="width: 100%">
		  	<el-option :value="0" label="否"></el-option>
		  	<el-option :value="1" label="是"></el-option>
		  </el-select>
        </el-form-item>
        <el-form-item label="是否推荐" prop="goodsIsRecommend">
		  <el-select v-model="form.goodsIsRecommend" placeholder="请选择消息类型" style="width: 100%">
		  	<el-option :value="0" label="否"></el-option>
		  	<el-option :value="1" label="是"></el-option>
		  </el-select>
        </el-form-item>
        <el-form-item label="是否热门" prop="goodsIsHot">
		  <el-select v-model="form.goodsIsHot" placeholder="请选择消息类型" style="width: 100%">
		  	<el-option :value="0" label="否"></el-option>
		  	<el-option :value="1" label="是"></el-option>
		  </el-select>
        </el-form-item>
        <el-form-item label="好评率" prop="goodsFavorableRate">
          <el-input v-model="form.goodsFavorableRate" placeholder="请输入好评率">
			  <template slot="append">%</template>
		  </el-input>
        </el-form-item>
        <el-form-item label="销量" prop="goodsSalesVolume">
          <el-input v-model="form.goodsSalesVolume" placeholder="请输入销量">
			   <template slot="append">个</template>
		  </el-input>
        </el-form-item>
        <el-form-item label="商品类型" prop="goodsTypeid">
         <el-select v-model="form.goodsTypeid" placeholder="请选择商品类型" style="width: 100%;">
			 <el-option v-for="(item,index) in type" :key = "index" :value="item.goodsTypeId" :label="item.goodsTypeTitle"></el-option>
		 </el-select>
        </el-form-item>
        <el-form-item label="商品品牌" prop="goodsBrandId">
			<el-select v-model="form.goodsBrandId" placeholder="请选择商品类型" style="width: 100%;">
				<el-option v-for="(item,index) in brand" :key = "index" :value="item.goodsBrandId" :label="item.goodsBrandName"></el-option>
			</el-select>
        </el-form-item>
        <el-form-item label="店铺名称" prop="goodsRoomsid">
			  <el-select v-model="form.goodsRoomsid" placeholder="请选择商品类型" style="width: 100%;">
			  	<el-option v-for="(item,index) in storeManagement" :key = "index" :value="item.storeManagementId" :label="item.storeManagementName"></el-option>
			  </el-select>
        </el-form-item>
        <el-form-item label="优惠券" prop="goodsDiscountId">
			<el-select v-model="form.goodsDiscountId" placeholder="请选择商品类型" style="width: 100%;">
				<el-option v-for="(item,index) in coupon" :key = "index" :value="item.discountCouponId" :label="item.discountCouponName"></el-option>
			</el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listGoods, getGoods, delGoods, addGoods, updateGoods, exportGoods ,uploadImgs } from "@/api/system/goods";
import {listType} from "@/api/system/type";
import {listBrand} from "@/api/system/brand";
import {listManagement} from "@/api/system/storeManagement";
import {listCoupon} from "@/api/system/coupon";
export default {
  name: "Goods",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 商品表格数据
      goodsList: [],
      // 弹出层标题
      title: "",
	  //开始
	  formDate: null,
	  uploadList: [],
	  dialogImageUrl: '',
	  dialogVisible: false,
	  imageList: [],
	  //结束
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        goodsName: undefined,
        goodsImages: undefined,
        goodsThumbnailImg: undefined,
        goodsStatus: undefined,
        goodsRepertory: undefined,
        goodsMoney: undefined,
        goodsTime: undefined,
        goodsDetails: undefined,
        goodsServerContent: undefined,
        goodsSource: undefined,
        goodsIndexShow: undefined,
        goodsIsNewproduct: undefined,
        goodsIsDiscount: undefined,
        goodsIsRecommend: undefined,
        goodsIsHot: undefined,
        goodsFavorableRate: undefined,
        goodsSalesVolume: undefined,
        goodsTypeid: undefined,
        goodsBrandId: undefined,
        goodsRoomsid: undefined,
        goodsDiscountId: undefined
      },
	  type:[],
	  brand:[],
	  storeManagement:[],
	  coupon:[],
	  goodsList:[],
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
	this.getType();
	this.getBrand();
	this.getStoreManagement();
	this.getCoupon();
  },
  methods: {
    /** 查询商品列表 */
    getList() {
      this.loading = true;
      listGoods(this.queryParams).then(response => {
        this.goodsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
	/* 查询商品类型 */
	getType() {
	  listType().then(response => {
	    this.type = response.rows;
	  });
	},
	
	/* 查询商品规格 */
	getBrand() {
	  listBrand().then(response => {
	    this.brand = response.rows;
	  });
	},
	/* 查询店铺 */
	getStoreManagement() {
	  listManagement().then(response => {
	    this.storeManagement = response.rows;
	  });
	},
	/* 查询优惠券 */
	getCoupon() {
	  listCoupon().then(response => {
	    this.coupon = response.rows;
	  });
	},
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
		this.imageList = [];
      this.form = {
        goodsId: undefined,
        goodsName: undefined,
        goodsImages: undefined,
        goodsThumbnailImg: undefined,
        goodsStatus: "0",
        goodsRepertory: undefined,
        goodsMoney: undefined,
        goodsTime: undefined,
        goodsDetails: undefined,
        goodsServerContent: undefined,
        goodsSource: undefined,
        goodsIndexShow: undefined,
        goodsIsNewproduct: undefined,
        goodsIsDiscount: undefined,
        goodsIsRecommend: undefined,
        goodsIsHot: undefined,
        goodsFavorableRate: undefined,
        goodsSalesVolume: undefined,
        goodsTypeid: undefined,
        goodsBrandId: undefined,
        goodsRoomsid: undefined,
        goodsDiscountId: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.goodsId)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加商品";
    },
	
	 /** 修改按钮操作 */
	    handleUpdate(row) {
	      this.reset();
	      const goodsId = row.goodsId || this.ids
	      getGoods(goodsId).then(response => {
	        if (response.data.goodsThumbnailImg != null && response.data.goodsThumbnailImg != '') {/* 判断图片的地址是否为空 */
	        	var imageList = response.data.goodsThumbnailImg.split(',');
	        	for (var i = 0; i < imageList.length; i++) {
	        		imageList[i] = imageList[i];
	        		this.imageList.push({
	        			name: imageList[i],
	        			url: imageList[i]
	        		});/*
	            alert(imageList+"：查询显示的路径"); */
	        	}
	        }
	        this.form = response.data;
	        this.open = true;
	        this.title = "修改话题";
	      });
	    },
    /** 提交按钮 */
    submitForm: function() {
		this.formDate = new FormData();//图片
		this.$refs.upload.submit();
		console.log(this.formDate);
		 if (this.uploadList.length > 0) {
		      	this.uploadList = [];
		      	uploadImgs(this.formDate).then(responses => {
		      		this.formDate = null;
		      		if (responses.code === 200) {
		      			this.$refs.upload.clearFiles();//清除上传列表
		      			var imageList = [];
		      			if (this.imageList != null) {
		      				for (var i = 0; i < this.imageList.length; i++) {
		      					if (this.imageList[i] != null) {
		      						imageList.push(this.imageList[i].name);
		      					}
		      				}
		      			}
		      			imageList = imageList.concat(responses.data);
		            console.log(responses.data);
		      			this.form.goodsThumbnailImg = imageList.join(',');
		      			this.submitForms();
		      		} else {
		      			this.msgError(responses.msg);
		      		}
		      	});
		      }else {
					this.formDate = null;
					var imageList = [];
					if (this.imageList != null) {
						for (var i = 0; i < this.imageList.length; i++) {
							if (this.imageList[i] != null) {
								imageList.push(this.imageList[i].name);
							}
						}
					}
					console.log(imageList);
					this.form.goodsThumbnailImg = imageList.join(',');
					this.submitForms();
				}
		},
		submitForms:function(){
			this.$refs["form"].validate(valid => {
			  if (valid) {
			    if (this.form.goodsId != undefined) {
			      updateGoods(this.form).then(response => {
			        if (response.code === 200) {
			          this.msgSuccess("修改成功");
			          this.open = false;
			          this.getList();
			        }
			      });
			    } else {
			      addGoods(this.form).then(response => {
			        if (response.code === 200) {
			          this.msgSuccess("新增成功");
			          this.open = false;
			          this.getList();
			        }
			      });
			    }
			  }
			});
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const goodsIds = row.goodsId || this.ids;
      this.$confirm('是否确认删除商品编号为"' + goodsIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delGoods(goodsIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有商品数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportGoods(queryParams);
        }).then(response => {
          this.download(response.msg);
        }).catch(function() {});
    },
	/** 图片操作 */
	   handleRemove(file, fileList) {//删除时
	   	for (var i = 0; i < this.imageList.length; i++) {
	   		if (this.imageList[i].url == file.url) {
	   			this.imageList.splice(i, 1);
	   		}
	   	}
	   },
	   handlePictureCardPreview(file) {//上传文件时
	     console.log(file.url);
	   	this.dialogImageUrl = file.url;
	   	this.dialogVisible = true;
	   },
	   imageChange(event, file, fileList) {//成功后
	    /* alert("123成功"); */
	   	console.log(event);
	   	console.log(file);
	   	console.log(fileList);
	   },
	   uploadFile(file) {//上传行为
	   	this.uploadList.push(file.file);
	   	this.formDate.append('file', file.file);
	     console.log(this.formDate.file);
	   }
  }
};
</script>